// components/user-profile-picture/index.js
const {
  othersApi,
} = require('../../api/index')
const {
  USERVIEWTYPE
} = require('../../utils/util')
const app= getApp()
Component({
  lifetimes: {
    attached() {
      if (this.properties.userID) {
        othersApi.getothers({
          UserId: this.properties.userID,
        }).then(res => {
          // console.log(res);
          this.setData({
            userData: res.Result,
            userAvatar:res.Result.Avatar || this.data.IMGBASEURL + "user_64.png"
          })
        })
      }else{
        this.setData({
          userData:this.properties.usreInfo,
          userAvatar:this.properties.usreInfo.Avatar || this.data.IMGBASEURL + "user_64.png"
        })
      }
    }
  },

  properties: {
    userID: {
      type: String,
      value: ''
    },
    usreInfo:{
      type: Object,
      value: {}
    },
    width: {
      type: String,
      value: '80'
    },
    hansIcon:{
      type:Boolean,
      value:true
    }
  },
  /**
   * 组件的初始数据
   */
  data: {
    userData: {},
    userAvatar:'',
    identityImg: USERVIEWTYPE,
    IMGBASEURL: app.globalData.IMGBASEURL,
  },

  /**
   * 组件的方法列表
   */
  methods: {
    goPage() {
      wx.navigateTo({
        url: `/pages/my/othersPage/index?id=${this.data.userData.UserId}`,
      })
    },
    onerror(e) {
      console.log(e,'========');
      this.setData({
        userAvatar:  this.data.IMGBASEURL + "user_64.png"
      })
    },
  }
})